package com.example.administrator.myapplication.data.source;

import com.example.administrator.myapplication.data.Task;
import com.example.administrator.myapplication.data.source.local.TaskLocalDataSource;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/27.
 */

public class TaskRepository implements TaskDataSource {

    private static TaskRepository instance;

    private TaskLocalDataSource mTaskLocalDataSource;
//
//    Map<String,Task> mCachedTasks;//缓存数据
//
//    private boolean isCacheDirty;//判断缓存是否可用

    private TaskRepository(TaskLocalDataSource taskLocalDataSource){
        this.mTaskLocalDataSource = taskLocalDataSource;
    }

    public static TaskRepository getInstance(TaskLocalDataSource taskLocalDataSource){
        if (instance == null){
            instance = new TaskRepository(taskLocalDataSource);
        }

        return instance;
    }


    @Override
    public void getTasks(final LoadTasksCallback callback) {
        mTaskLocalDataSource.getTasks(callback);
    }

    @Override
    public void getSearchedTasks(String selectionContent, LoadSerachedTasksCallback callback) {
        mTaskLocalDataSource.getSearchedTasks(selectionContent,callback);
    }

    @Override
    public void getTask(String id, GetTaskCallback callback) {
        mTaskLocalDataSource.getTask(id,callback);
    }

    @Override
    public void saveTask(Task task) {
        mTaskLocalDataSource.saveTask(task);
    }

    @Override
    public void updateTask(Task task) {
        mTaskLocalDataSource.updateTask(task);
    }
}
